/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kh.pi.MediaView;

import com.kh.pi.Playlist.PlayList;
import java.util.List;
import javafx.application.Application;
import javafx.application.HostServices;
import javafx.beans.binding.Bindings;
import javafx.beans.property.DoubleProperty;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;

import com.kh.pi.Playlist.PlayList;
/**
 *
 * @author phamt_000
 */
public class PiMediaView implements com.kh.pi.Interface.IMediaView{
    MediaView mediaView;
    List<MediaPlayer> playlist;
    public PiMediaView(List<MediaPlayer> plist){
        mediaView = new MediaView();
        playlist=plist;
    }
//    @Override
//    public void setNextPlay(){
//        //set next player 
//        for(int i = 0; i<playlist.size();i++){
//            final MediaPlayer player     = playlist.get(i);
//            final MediaPlayer nextPlayer = playlist.get((i + 1) % playlist.size());
////            player.setOnEndOfMedia(new Runnable() {
////              @Override public void run() {
////                mediaView.setMediaPlayer(nextPlayer);
////                nextPlayer.play();
////              }
////            });
//
//        }
//    }
    @Override
    public MediaView getMediaView(){
        final DoubleProperty width = mediaView.fitWidthProperty();
        final DoubleProperty height = mediaView.fitHeightProperty();
        width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
        height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));
        
        mediaView.setPreserveRatio(true);
        mediaView.setMediaPlayer(playlist.get(0));
        return mediaView;
    }
//    @Override
//    public MediaView Create(HostServices host,List<MediaPlayer> playlist){
//        
//       
//        
//        
//        //Begin: make video fullscreen {
//        final DoubleProperty width = mediaView.fitWidthProperty();
//        final DoubleProperty height = mediaView.fitHeightProperty();
//        width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
//        height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));
//        
//        mediaView.setPreserveRatio(true);
//        mediaView.setMediaPlayer(playlist.get(0));
//        return mediaView;
//    }
}
